import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import systemRouter from "./systemRouter";

//系统特殊路由
const routes_404 = {
	path: "/:pathMatch(.*)*",
	hidden: true,
	component: () => import("@/layout/404.vue"),
};

const routes: RouteRecordRaw[] = systemRouter;
const router = createRouter({
	history: createWebHistory(),
	routes: [...routes, routes_404],
	scrollBehavior() {
		return { top: 0 };
	},
});

router.beforeEach(() => {
	NProgress.start();
});

router.afterEach(() => {
	NProgress.done();
});

router.onError((error) => {
	NProgress.done();
	ElNotification.error({
		title: "路由错误",
		message: error.message,
	});
});
export default router;
